package logic

import (
	"bw-renting/house-rpc/house"
	"context"

	"bw-renting/api/internal/svc"
	"bw-renting/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateHouseLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCreateHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateHouseLogic {
	return &CreateHouseLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// TODO: 添加房源
func (l *CreateHouseLogic) CreateHouse(req *types.CreateHouseReq) (resp *types.Data, err error) {
	// todo: add your logic here and delete this line
	res, _ := l.svcCtx.HouseServer.CreateHouse(context.Background(), &house.CreateHouseReq{
		UserId:    int64(req.UserId),
		Title:     req.Title,
		AreaId:    int64(req.AreaId),
		Price:     float32(req.Price),
		Address:   req.Address,
		RoomCount: int64(req.RoomCount),
		Acreage:   int64(req.Acreage),
		Unit:      req.Unit,
		CoverUrl:  req.CoverUrl,
	})
	if res.Status == "0" {
		return &types.Data{
			Code:    10001,
			Message: "发布房源失败",
			Data: map[string]string{
				"houseId": res.Status,
			},
		}, nil
	}
	return &types.Data{
		Code:    200,
		Message: "发布房源成功",
		Data: map[string]string{
			"houseId": res.Status,
		},
	}, nil
}
